//ognl格式转换工具类
package com.sy.util;

import java.util.Map;

import ognl.DefaultTypeConverter;

import com.sy.bean.Point;

public class PointConverter extends DefaultTypeConverter {

	@SuppressWarnings("unchecked")
	public Object convertValue(Map context, Object value, Class toType) {
		if(Point.class==toType){//如果目标类型是Point
			
			Point point=new Point();
			String[] str=(String[])value;//value是字符串数组，在这里强行转换为字符串
			String[] paramValues=str[0].split(",");//字符串用","分割为字符串数组
			int x=Integer.parseInt(paramValues[0]);
			int y=Integer.parseInt(paramValues[1]);
			point.setX(x);
			point.setY(y);
			return point;
		}
		if(String.class==toType){//如果目标类型是String
			Point point=(Point)value;//转换成Point类型
			int x=point.getX();
			int y=point.getY();
			String result="[x="+x+",y="+y+"]";
			return result;
		}
		return null;
	}

	
}
